//
//  MessageSorterPreferences_Extras.m
//  funkydog
//
//  Created by Saptarshi Guha on 2/1/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "MessageSorterPreferences_Extras.h"
#import <objc/objc.h>
#import <objc/objc-runtime.h>
#import <objc/objc-class.h>

#import "TagRuleAction.h"

@implementation MailSorterPreferences(Extras)
static NSMapTable *_MYSimulatedIVarMapTable = NULL;
+ (NSMapTable *)_mySimulatedIVarMapTable
{
	if(NULL == _MYSimulatedIVarMapTable) _MYSimulatedIVarMapTable = 
		NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks, NSObjectMapValueCallBacks, 16);
	return _MYSimulatedIVarMapTable;	
}
- (void)mySetUserInfo:(NSMutableDictionary *)aDictionary
{
	NSMutableDictionary    *newDictionary = [aDictionary copy];
	NSMapInsert([[self class] _mySimulatedIVarMapTable], self, newDictionary);
	[newDictionary release];
}
- (NSMutableDictionary *)myUserInfo
{
	return (NSMutableDictionary*)NSMapGet([[self class] _mySimulatedIVarMapTable], self);
}

+(void)load{
	if (self == [MailSorterPreferences class]){
		Method originalMethod ,replacedMethod;
		originalMethod  = class_getInstanceMethod(self, @selector(_validateActionMenuItem:currentTag:));
		replacedMethod  = class_getInstanceMethod(self, @selector(my_validateActionMenuItem:currentTag:));
	//	method_exchangeImplementations(originalMethod, replacedMethod);
		originalMethod  = class_getInstanceMethod(self, @selector(actionPopupWillPopup:));
		replacedMethod  = class_getInstanceMethod(self, @selector(myactionPopupWillPopup:));
	//	method_exchangeImplementations(originalMethod, replacedMethod);
		originalMethod  = class_getInstanceMethod(self, @selector(actionPopupChanged:));
		replacedMethod  = class_getInstanceMethod(self, @selector(myactionPopupChanged:));
	//	method_exchangeImplementations(originalMethod, replacedMethod);
		originalMethod  = class_getInstanceMethod(self, @selector(_actionViewForTag:));
		replacedMethod  = class_getInstanceMethod(self, @selector(my_actionViewForTag:));
	//	method_exchangeImplementations(originalMethod, replacedMethod);
		originalMethod  = class_getInstanceMethod(self, @selector(dealloc));
		replacedMethod  = class_getInstanceMethod(self, @selector(mydealloc));
		method_exchangeImplementations(originalMethod, replacedMethod);
		originalMethod  = class_getInstanceMethod(self, @selector(removeAction:));
		replacedMethod  = class_getInstanceMethod(self, @selector(myremoveAction:));
	//	method_exchangeImplementations(originalMethod, replacedMethod);
	//	originalMethod  = class_getInstanceMethod(self, @selector(_configureActionsForRule:));
//		replacedMethod  = class_getInstanceMethod(self, @selector(my_configureActionsForRule:));
//		method_exchangeImplementations(originalMethod, replacedMethod);
//		originalMethod  = class_getInstanceMethod(self, @selector(applyRulesSheetDidEnd:returnCode:contextInfo:));
//		replacedMethod  = class_getInstanceMethod(self, @selector(myapplyRulesSheetDidEnd:returnCode:contextInfo:));
//		method_exchangeImplementations(originalMethod, replacedMethod);
//		
		
	}
}
-(void)myapplyRulesSheetDidEnd:(id)fp8 returnCode:(int)fp12 contextInfo:(void *)fp16{
	NSLog(@"[mvp myapplyRulesSheetDidEnd:%@ contextinfo:%p",fp8,fp16);
	[self myapplyRulesSheetDidEnd:fp8 returnCode:fp12 contextInfo:fp16];
}
-(void)my_configureActionsForRule:(id)fp8{
	NSLog(@"[mvp my_configureActionsForRule:%@",fp8);
	[self my_configureActionsForRule:fp8];
}
- (void)myremoveAction:(id)fp8{
	if([fp8 tag]==397) {
		[[ [ self myUserInfo] objectForKey:@"TagRuleAction"] release];
		[self mySetUserInfo:[ NSMutableDictionary dictionaryWithCapacity:1]];
	}
	[self myremoveAction:fp8];
}
-(void)mydealloc{
	NSMapRemove([[self class] _mySimulatedIVarMapTable], self);
	[self mydealloc];
}
- (void)my_validateActionMenuItem:(id)fp8 currentTag:(int)fp12{
	[self my_validateActionMenuItem:fp8 currentTag:fp12];
	}
-(void)myactionPopupChanged:(id)fp8
{
	[self myactionPopupChanged:fp8];
}
-(id)my_actionViewForTag:(int)fp8{
	id x=[self my_actionViewForTag:fp8];
//	if (fp8==397){
//		TagRuleAction *c=(TagRuleAction*)[ [ self myUserInfo] objectForKey:@"TagRuleAction"];
//		if(!c)	c=[ [TagRuleAction alloc] init];
//		x=[c addTagView];
//		[self mySetUserInfo:[ NSMutableDictionary dictionaryWithObject:c forKey:@"TagRuleAction"]];
//		[[c tagadd] setTarget:self]; [[c tagadd] setAction:@selector(addAction:)];
//		[[c tagactions] setTarget:self];[[c tagactions] setAction:@selector(actionPopupChanged:)];
//		[[c tagremove] setTarget:self]; [[c tagremove] setAction:@selector(removeAction:)];
//	}
	return x;
} 
-(void)myactionPopupWillPopup:(id)fp8{
	NSPopUpButtonCell *npc=[fp8 object];
	[self myactionPopupWillPopup:fp8];
	//[npc addItemWithTitle:@"Set Tags"];[ [npc itemWithTitle:@"Set Tags"] setTag:397];
//	if([ [ self myUserInfo] objectForKey:@"TagRuleAction"]) {
//		[ [npc itemWithTitle:@"Set Tags"] setEnabled:NO];
//	}
}
@end
